package club.vann.kafka.mock.service;

import club.vann.kafka.mock.kafka.KafkaProducer;
import club.vann.kafka.mock.kafka.KafkaTopicFactory;
import club.vann.kafka.mock.util.QuoteActionUtil;
import com.cyberx.lunyu.QuoteOuterClass;
import java.util.HashMap;
import java.util.Map;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@RequiredArgsConstructor
@Service
public class QuoteActionService {
  private final KafkaProducer kafkaProducer;

  /**
   * 推送报价结果。
   *
   * @param clientId ClientId
   * @param id ID
   */
  public void actionResult(String clientId, String id, String venue, String ticker) {
    Map<String, String> dataMap = new HashMap<>();
    dataMap.put("CLIENT_ID", clientId);
    dataMap.put("ID", id);
    dataMap.put("VENUE", venue);
    dataMap.put("TICKER", ticker);
    QuoteOuterClass.Quote.QuoteActionResult quoteActionResult =
        QuoteActionUtil.ofQuoteActionResult(dataMap);
    this.kafkaProducer.send(
        KafkaTopicFactory.QUOTE_ACTION_OUTPUT, clientId, quoteActionResult.toByteArray());
  }
}
